<template>
  <div class="diamond-node">
    <!-- 顶部连接点：source 和 target -->
    <Handle type="target" position="top" class="handle" id="top-target" />
    <Handle type="source" position="top" class="handle" id="top-source" />
    <!-- 左侧连接点：source 和 target -->
    <Handle type="target" position="left" class="handle" id="left-target" />
    <Handle type="source" position="left" class="handle" id="left-source" />
    <!-- 右侧连接点：source 和 target -->
    <Handle type="target" position="right" class="handle" id="right-target" />
    <Handle type="source" position="right" class="handle" id="right-source" />
    <!-- 底部连接点：source 和 target -->
    <Handle type="target" position="bottom" class="handle" id="bottom-target" />
    <Handle type="source" position="bottom" class="handle" id="bottom-source" />
    <!-- 节点本体 -->
    <div class="diamond">
      <div class="label">{{ data.label }}</div>
    </div>
  </div>
</template>

<script setup>
import { Handle } from '@vue-flow/core'

defineProps({
  data: Object,
})
</script>

<style scoped>
.diamond-node {
  position: relative;
  width: 80px;
  height: 80px;
  overflow: visible;
}

.diamond {
  width: 100%;
  height: 100%;
  background: #2ec4b6;
  transform: rotate(45deg);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #333;
  color: white;
  font-weight: bold;
  box-sizing: border-box;
  z-index: 1;
}

.label {
  transform: rotate(-45deg);
  text-align: center;
  pointer-events: none;
  font-size: 12px;
  padding: 4px;
  max-width: 90%;
  word-break: break-all;
}

.handle {
  width: 10px;
  height: 10px;
  background: #ff0000;
  border-radius: 50%;
  position: absolute;
  z-index: 2;
}

:deep(.vue-flow__handle-top) {
  top: -10px; /* 增加偏移量，使点移到顶部外部 */
  left: 50%;
  transform: translateX(-50%);
}

:deep(.vue-flow__handle-bottom) {
  bottom: -10px; /* 增加偏移量，使点移到底部外部 */
  left: 50%;
  transform: translateX(-50%);
}

:deep(.vue-flow__handle-left) {
  left: -10px; /* 增加偏移量，使点移到左侧外部 */
  top: 50%;
  transform: translateY(-50%);
}

:deep(.vue-flow__handle-right) {
  right: -10px; /* 增加偏移量，使点移到右侧外部 */
  top: 50%;
  transform: translateY(-50%);
}
</style>
